package com.example.smartwaterapi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartwaterapi.entity.WaterAchievement;
import com.example.smartwaterapi.mapper.WaterAchievementMapper;
import com.example.smartwaterapi.service.WaterAchievementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * 饮水成就服务实现类
 */
@Slf4j
@Service
public class WaterAchievementServiceImpl extends ServiceImpl<WaterAchievementMapper, WaterAchievement> implements WaterAchievementService {

    @Override
    public boolean save(WaterAchievement entity) {
        log.info("保存饮水成就数据: {}", entity);
        try {
            boolean result = super.save(entity);
            if (result) {
                log.info("饮水成就数据保存成功, id: {}", entity.getId());
            } else {
                log.error("饮水成就数据保存失败");
            }
            return result;
        } catch (Exception e) {
            log.error("保存饮水成就数据异常", e);
            throw e;
        }
    }
    
    @Override
    public boolean updateById(WaterAchievement entity) {
        log.info("更新饮水成就数据, id: {}", entity.getId());
        try {
            boolean result = super.updateById(entity);
            if (result) {
                log.info("饮水成就数据更新成功, id: {}", entity.getId());
            } else {
                log.warn("饮水成就数据更新失败, id: {}, 可能记录不存在", entity.getId());
            }
            return result;
        } catch (Exception e) {
            log.error("更新饮水成就数据异常, id: {}", entity.getId(), e);
            throw e;
        }
    }
    
    @Override
    public WaterAchievement getById(Serializable id) {
        log.info("获取饮水成就数据, id: {}", id);
        try {
            WaterAchievement achievement = super.getById(id);
            if (achievement == null) {
                log.warn("未找到饮水成就数据, id: {}", id);
            }
            return achievement;
        } catch (Exception e) {
            log.error("获取饮水成就数据异常, id: {}", id, e);
            throw e;
        }
    }
    
    @Override
    public boolean removeById(Serializable id) {
        log.info("删除饮水成就数据, id: {}", id);
        try {
            boolean result = super.removeById(id);
            if (result) {
                log.info("饮水成就数据删除成功, id: {}", id);
            } else {
                log.warn("饮水成就数据删除失败, id: {}, 可能记录不存在", id);
            }
            return result;
        } catch (Exception e) {
            log.error("删除饮水成就数据异常, id: {}", id, e);
            throw e;
        }
    }
}
